package com.my.hotel.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.my.hotel.entity.EvaDTO;
import com.my.hotel.service.EvaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/eva")
public class EvaController {

    @Autowired
    private EvaService evaService;

    @RequestMapping("/getEvaDTOList")
    public String getEvaDTOList(Integer pageNo, Model model){
        if (null == pageNo){
            pageNo=1;
        }
        PageHelper.startPage(pageNo,5);
        List<EvaDTO> evaDTOList = evaService.getEvaDTOList();
        PageInfo<EvaDTO> pageInfo = new PageInfo<EvaDTO>(evaDTOList);
        model.addAttribute("page",pageInfo);
        return "evaPage";
    }

    @RequestMapping("/checkEva")
    public String checkEva(Integer id,String appStatus,Model model){
        if ("0".equals(appStatus)){
            appStatus="1";
            evaService.checkEva(appStatus,id);
            return getEvaDTOList(model);
        }else {
            appStatus="0";
            evaService.checkEva(appStatus,id);
            return getEvaDTOList(model);
        }
    }

    public String getEvaDTOList(Model model){
        return getEvaDTOList(1,model);
    }
}
